package com.chenyaowei.web.controller.product.spu;

import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.core.page.TableDataInfo;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.product.domain.CywProSpuInfo;
import com.chenyaowei.product.service.ICywProSpuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * spu信息Controller
 *
 * @author 陈耀威
 * @date 2023-11-24
 */
@RestController
@RequestMapping("/product/spuInfo")
public class CywProSpuInfoController extends BaseController
{
    @Autowired
    private ICywProSpuInfoService cywProSpuInfoService;

    @PutMapping("/upPublish/{spuId}")
    public AjaxResult upPublishProduct(@PathVariable("spuId") Long spuId)
    {
        return toAjax(cywProSpuInfoService.upPublishProduct(spuId));
    }

    @PutMapping("/downPublish/{spuId}")
    public AjaxResult downPublishProduct(@PathVariable("spuId") Long spuId)
    {
        return toAjax(cywProSpuInfoService.downPublishProduct(spuId));
    }

    /**
     * 查询spu信息列表
     */
    @PreAuthorize("@ss.hasPermi('product:spuInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywProSpuInfo cywProSpuInfo)
    {
        startPage();
        List<CywProSpuInfo> list = cywProSpuInfoService.selectCywProSpuInfoList(cywProSpuInfo);
        return getDataTable(list);
    }

    /**
     * 导出spu信息列表
     */
    @PreAuthorize("@ss.hasPermi('product:spuInfo:export')")
    @Log(title = "spu信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywProSpuInfo cywProSpuInfo)
    {
        List<CywProSpuInfo> list = cywProSpuInfoService.selectCywProSpuInfoList(cywProSpuInfo);
        ExcelUtil<CywProSpuInfo> util = new ExcelUtil<CywProSpuInfo>(CywProSpuInfo.class);
        util.exportExcel(response, list, "spu信息数据");
    }

    /**
     * 获取spu信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:spuInfo:query')")
    @GetMapping(value = "/{spuId}")
    public AjaxResult getInfo(@PathVariable("spuId") Long spuId)
    {
        return success(cywProSpuInfoService.selectCywProSpuInfoBySpuId(spuId));
    }

    /**
     * 新增spu信息
     */
    @PreAuthorize("@ss.hasPermi('product:spuInfo:add')")
    @Log(title = "spu信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywProSpuInfo cywProSpuInfo)
    {
        return toAjax(cywProSpuInfoService.insertCywProSpuInfo(cywProSpuInfo));
    }

    /**
     * 修改spu信息
     */
    @PreAuthorize("@ss.hasPermi('product:spuInfo:edit')")
    @Log(title = "spu信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywProSpuInfo cywProSpuInfo)
    {
        return toAjax(cywProSpuInfoService.updateCywProSpuInfo(cywProSpuInfo));
    }

    /**
     * 删除spu信息
     */
    @PreAuthorize("@ss.hasPermi('product:spuInfo:remove')")
    @Log(title = "spu信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{spuIds}")
    public AjaxResult remove(@PathVariable Long[] spuIds)
    {
        return toAjax(cywProSpuInfoService.deleteCywProSpuInfoBySpuIds(spuIds));
    }
}
